package de.softwareforge.published.util;

/*
 * Copyright (C) 2007-2008 Henning P. Schmiedehausen
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import com.sun.javadoc.Doc;
import com.sun.javadoc.SourcePosition;
import com.sun.javadoc.Tag;

import de.softwareforge.published.taglet.PublishedTaglet;


/**
 * A synthesized Tag used to sneak in Tag information if a parent demands it.
 *
 * @author <a href="mailto:henning@schmiedehausen.org">Henning P. Schmiedehausen</a>
 * @version $Id:PublishedStatusTag.java 357 2007-08-13 20:57:20Z hps@intermeta.de $
 * @api.level unpublished
 */
public class PublishedStatusTag
        implements Tag
{

    private final Doc document;
    private final PublishedStatus status;

    /**
     * Creates a new PublishedStatusTag object. Do not optimize the PublishedStatus element out, it might be necessary to actually
     * change the PublishInformation while this tag has already been assigned to an element. So we need a layer to do this.
     *
     * @param document The document which gets this tag.
     * @param status publishInformation The status to display in this tag.
     */
    public PublishedStatusTag(final Doc document, final PublishedStatus status)
    {
        this.document = document;
        this.status = status;
    }

    /**
     * @see Tag#firstSentenceTags()
     */
    public Tag[] firstSentenceTags()
    {
        return new Tag[0];
    }

    /**
     * @see Tag#holder()
     */
    public Doc holder()
    {
        return document;
    }

    /**
     * @see Tag#inlineTags()
     */
    public Tag[] inlineTags()
    {
        return new Tag[0];
    }

    /**
     * @see Tag#kind()
     */
    public String kind()
    {
        return name();
    }

    /**
     * @see Tag#name()
     */
    public String name()
    {
        return PublishedTaglet.NAME;
    }

    /**
     * @see Tag#position()
     */
    public SourcePosition position()
    {
        return document.position();
    }

    /**
     * @see Tag#text()
     */
    public String text()
    {
        return String.valueOf(status.getPublishInformation());
    }

    /**
     * @see Tag#toString()
     */
    @Override
    public String toString()
    {
        return name() + ":" + text();
    }
}
